clear all
set more off
set maxvar 10000

	use "$Mydirectory1/3_Output/2_PooledData_analysis.dta", clear 
    
    forval i=1(1)8 {
        gen beta_`i'=.
    }

* Select sample
    gen sample_men = baseline_sample==1 & sex==1 & log_son_interpolated!=. 
    keep if sample_men==1
    
    tempfile data1
    save `data1'

* Run regressions   
    foreach version in whitemen allmen {

        use `data1', clear 
        
        if "`version'"=="whitemen" local cond "race==1 &"
        if "`version'"=="allmen" local cond " "
        
        forval d=1/7 { 
            
            // White men, 1950 IPUMS occscore (father and son)
            reg log_son_occscore log_father_1950occscore  if `cond' decade==19`d'0  [pw=wgt_sex_race], robust
            replace beta_1=_b[log_father_1950occscore] if decade==19`d'0 

            // White men, baseline predicted father income
            reg log_son_occscore log_father_baseline if  `cond' decade==19`d'0  [pw=wgt_sex_race], robust
            replace beta_2=_b[log_father_baseline] if decade==19`d'0 
                
            // White men, predicted son income
            reg log_son_interpolated log_father_baseline  if  `cond' decade==19`d'0  [pw=wgt_sex_race], robust
            replace beta_3=_b[log_father_baseline] if decade==19`d'0

            // White men, son family income (logged)
            reg log_son_baseline log_father_baseline if  `cond' decade==19`d'0  [pw=wgt_sex_race], robust
            replace beta_4=_b[log_father_baseline] if decade==19`d'0 
                
        }   

        sort decade 
        keep beta_* decade
        bysort decade: keep if _n==1

        #delimit ;
        twoway  (connect beta_1 decade , msymbol(square) mc(black) lc(black))
                (connect beta_2 decade , msymbol(square_hollow) mc(gray) lc(gray) lpat(solid)) 
                (connect beta_3 decade ,  msymbol(diamond) mc(midblue*0.7) lc(midblue*0.7))
                (connect beta_4 decade ,  msymbol(triangle_hollow) mc(purple) lc(purple) lpat(solid))
        , 
        legend(on size(medsmall) order(1 "IPUMS score for both" 2 "+father race/South score" 
        3 "+son race/South score" 4 "+son family inc."))
        ylabel(0.15(.1).65, axis(1)) yti("IGE coefficient" " ", axis(1))
        xtitle(" " "Decade of respondent's birth") xlabel(1910 "1910s" 1920 "1920s" 1930 "1930s" 1940 "1940s" 1950 "1950s" 1960 "1960s" 1970 "1970s", labsize(small) ); 
        #delimit cr
        
        graph export "$Mydirectory2/appendix_a/IGE_various_measures_`version'.pdf", replace 

    }

